package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.AWechatMiniProgramUsers;
import com.ruoyi.lock.service.IAWechatMiniProgramUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 小程序用户Controller
 * 
 * @author ruoyi
 * @date 2024-08-09
 */
@RestController
@RequestMapping("/lock/smallUsers")
public class AWechatMiniProgramUsersController extends BaseController
{
    @Autowired
    private IAWechatMiniProgramUsersService aWechatMiniProgramUsersService;

    /**
     * 查询小程序用户列表
     */
    @PreAuthorize("@ss.hasPermi('lock:smallUsers:list')")
    @GetMapping("/list")
    public TableDataInfo list(AWechatMiniProgramUsers aWechatMiniProgramUsers)
    {
        startPage();
        List<AWechatMiniProgramUsers> list = aWechatMiniProgramUsersService.selectAWechatMiniProgramUsersList(aWechatMiniProgramUsers);
        return getDataTable(list);
    }

    /**
     * 导出小程序用户列表
     */
    @PreAuthorize("@ss.hasPermi('lock:smallUsers:export')")
    @Log(title = "小程序用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AWechatMiniProgramUsers aWechatMiniProgramUsers)
    {
        List<AWechatMiniProgramUsers> list = aWechatMiniProgramUsersService.selectAWechatMiniProgramUsersList(aWechatMiniProgramUsers);
        ExcelUtil<AWechatMiniProgramUsers> util = new ExcelUtil<AWechatMiniProgramUsers>(AWechatMiniProgramUsers.class);
        util.exportExcel(response, list, "小程序用户数据");
    }

    /**
     * 获取小程序用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:smallUsers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aWechatMiniProgramUsersService.selectAWechatMiniProgramUsersById(id));
    }

    /**
     * 新增小程序用户
     */
    @PreAuthorize("@ss.hasPermi('lock:smallUsers:add')")
    @Log(title = "小程序用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AWechatMiniProgramUsers aWechatMiniProgramUsers)
    {
        return toAjax(aWechatMiniProgramUsersService.insertAWechatMiniProgramUsers(aWechatMiniProgramUsers));
    }

    /**
     * 修改小程序用户
     */
    @PreAuthorize("@ss.hasPermi('lock:smallUsers:edit')")
    @Log(title = "小程序用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AWechatMiniProgramUsers aWechatMiniProgramUsers)
    {
        return toAjax(aWechatMiniProgramUsersService.updateAWechatMiniProgramUsers(aWechatMiniProgramUsers));
    }

    /**
     * 删除小程序用户
     */
    @PreAuthorize("@ss.hasPermi('lock:smallUsers:remove')")
    @Log(title = "小程序用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aWechatMiniProgramUsersService.deleteAWechatMiniProgramUsersByIds(ids));
    }
}
